}
/**
+ * Returns a lost of updates to perform when the given content is deleted.
+ * The necessary updates may be taken from the Content object, or depend on the current state of the database.
+ *
* @since WD.1
*
- * @param $page WikiPage the page that was deleted (note: $page->getId() must still return the old page ID!)
+ * @param \Content $content the Content object for deletion
+ * @param \Title $title the title of the deleted page
+ * @param null|\ParserOutput $parserOutput optional parser output object for efficient access to meta-information
+ * about the content object. Provide if you have one handy.
*
* @return array a list of DataUpdate instances that will clean up the database ofter deletion.
*/
- public function getDeletionUpdates( WikiPage $page ) {
+ public function getDeletionUpdates( Content $content, Title $title, ParserOutput $parserOutput = null ) {
return array(
- new LinksDeletionUpdate( $page ),
+ new LinksDeletionUpdate( $title ),
);
}
}
**/
class LinksDeletionUpdate extends SqlDataUpdate {
- protected $mPage; //!< WikiPage the wikipage that was deleted
+ protected $mTitle; //!< Title the title of page that was deleted
/**
* Constructor
* @param $parserOutput ParserOutput: output from a full parse of this page
* @param $recursive Boolean: queue jobs for recursive updates?
*/
- function __construct( WikiPage $page ) {
+ function __construct( Title $title ) {
parent::__construct( );
- $this->mPage = $page;
+ $this->mTitle = $title;
}
/**
* Do some database updates after deletion
*/
public function doUpdate() {
- $title = $this->mPage->getTitle();
- $id = $this->mPage->getId();
+ $title = $this->mTitle;
+ $id = $title->getArticleID();
# Delete restrictions for it
$this->mDb->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ );
$cats [] = $row->cl_to;
}
- $this->mPage->updateCategoryCounts( array(), $cats );
+ $this->updateCategoryCounts( array(), $cats );
# If using cascading deletes, we can skip some explicit deletes
if ( !$this->mDb->cascadingDeletes() ) {
__METHOD__ );
}
}
+
+ /**
+ * Update all the appropriate counts in the category table.
+ * @param $added array associative array of category name => sort key
+ * @param $deleted array associative array of category name => sort key
+ */
+ function updateCategoryCounts( $added, $deleted ) {
+ $a = WikiPage::factory( $this->mTitle );
+ $a->updateCategoryCounts(
+ array_keys( $added ), array_keys( $deleted )
+ );
+ }
}
}
# Update the links tables and other secondary data
- $updates = $editInfo->output->getSecondaryDataUpdates( $this->getTitle() );
+ $updates = $editInfo->output->getSecondaryDataUpdates( $this->getTitle() ); #FIXME: call ContentHandler::getSecondaryLinkUpdates. Don't parse iuf not needed! But don't parse too early either, only after saving, so we have an article ID!
DataUpdate::runUpdates( $updates );
wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
$bitfield = 'rev_deleted';
}
+ // we need to remember the old content so we can use it to generate all deletion updates.
+ $content = $this->getContent( Revision::RAW );
+
$dbw = wfGetDB( DB_MASTER );
$dbw->begin( __METHOD__ );
// For now, shunt the revision data into the archive table.
return WikiPage::DELETE_NO_REVISIONS;
}
- $this->doDeleteUpdates( $id );
+ $this->doDeleteUpdates( $id, $content );
# Log the deletion, if the page was suppressed, log it at Oversight instead
$logtype = $suppress ? 'suppress' : 'delete';
* Do some database updates after deletion
*
* @param $id Int: page_id value of the page being deleted (B/C, currently unused)
+ * @param $content Content: optional page content to be used when determining the required updates.
+ * This may be needed because $this->getContent() may already return null when the page proper was deleted.
*/
- public function doDeleteUpdates( $id ) {
+ public function doDeleteUpdates( $id, Content $content = null ) {
# update site status
DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 ) );
# remove secondary indexes, etc
- $updates = $this->getDeletionUpdates( );
+ $updates = $this->getDeletionUpdates( $content );
DataUpdate::runUpdates( $updates );
# Clear caches
* roll back to, e.g. user is the sole contributor. This function
* performs permissions checks on $user, then calls commitRollback()
* to do the dirty work
- *
+ *
* @todo: seperate the business/permission stuff out from backend code
*
* @param $fromP String: Name of the user whose edits to rollback.
return $this->isParserCacheUsed( ParserOptions::newFromUser( $wgUser ), $oldid );
}
- public function getDeletionUpdates() {
- $updates = $this->getContentHandler()->getDeletionUpdates( $this );
+ /**
+ * Returns a list of updates to be performed when this page is deleted. The updates should remove any infomration
+ * about this page from secondary data stores such as links tables.
+ *
+ * @param Content|null $content optional Content object for determining the necessary updates
+ * @return Array an array of DataUpdates objects
+ */
+ public function getDeletionUpdates( Content $content = null ) {
+ if ( !$content ) {
+ // load content object, which may be used to determine the necessary updates
+ // XXX: the content may not be needed to determine the updates, then this would be overhead.
+ $content = $this->getContent( Revision::RAW );
+ }
+
+ $updates = $this->getContentHandler()->getDeletionUpdates( $content, $this->mTitle );
wfRunHooks( 'WikiPageDeletionUpdates', array( $this, &$updates ) );
return $updates;